﻿using UnityEngine;
using System.Collections;
using System;
using System.Text;

public class Oc_ItemShowBox : ObjectBase
{
    const int RareMax = 6;
    const float StarCenter = -390.0f;
    const float StarOnCenter = 20.0f;
    const float StarGap = 27.0f;

    [NonSerialized]
    public Item m_Item;
    bool m_IsOn = false;

    public GameObject m_OnPanel;
    public GameObject m_OffPanel;
      
    public UISprite m_ItemSp;

    public UILabel m_ItemName;
   
    bool m_IsSetDetail = false;

    public Transform m_RareRoot;
    Transform[] m_Rare;

	public void SetItem(Item item, bool isLeft)
    {     
        m_Item = item;
       
        if (m_Item == null)
        {
            m_OnPanel.SetActive(false);
            m_OffPanel.SetActive(true);
            return;
        }

        m_OnPanel.SetActive(true);
        m_OffPanel.SetActive(false);

        WeaponAtlasController.SetWeaponSprite(m_ItemSp, m_Item);
        //m_ItemSp.spriteName = TextController.GetItemDefine(m_Item);

        UILabel powerText = m_ItemSp.transform.parent.Find("power").GetComponent("UILabel") as UILabel;
        if (m_Item.level > 0)
            powerText.text = string.Format("+{0}", m_Item.level);
        else
            powerText.text = "";

        m_ItemName.text = TextController.GetItemName(m_Item);

        UISprite itemBg = m_ItemSp.transform.GetChild(0).GetComponent("UISprite") as UISprite;
        itemBg.color = Constants.GetItemBGRareColorValue(m_Item.itemInfo.rarity);


        if (m_Rare == null)
        {
            m_Rare = new Transform[RareMax];
            for (int i = 0; i < RareMax; i++)
            {
                m_Rare[i] = m_RareRoot.Find(string.Format("Rare_{0}", i + 1));
            }
        }


        for (int i = 0; i < RareMax; i++)
        {
            m_Rare[i].gameObject.SetActive(m_Item.itemInfo.rarity == i + 1);
        }


        UIPanel pn = m_ItemName.parent.GetComponent("UIPanel") as UIPanel;
        if (m_Item.itemInfo.part == 3 && isLeft)
            pn.alpha = 0.6f;
        else
            pn.alpha = 1.0f;

        m_IsSetDetail = false;  //아이템 바뀌면 디테일 다시 설정 필요
    }
}
